Attribute VB_Name = "ModuloDatos"
Public cn As ADODB.Connection
Public rs As Recordset
Public BAN As Integer
Public variable As Integer
Public cliente As Integer
Public rsaux As Recordset
Public rsa As Recordset
Public rsimprime As Recordset
Public Type typecombo
    item As String
    text As String
End Type

Public Sub desconectar()
    If Not rs.State = adStateClosed Then rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
End Sub
 
Public Sub Conectar()
    Set cn = New ADODB.Connection
    cn.Open frmLogin.gCadenaConexion
    cn.CursorLocation = adUseClient
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.CursorType = adOpenStatic
    rs.LockType = adLockOptimistic
    Set rs.ActiveConnection = cn
    
    Set rsaux = New ADODB.Recordset
    rsaux.CursorLocation = adUseClient
    rsaux.CursorType = adOpenStatic
    rsaux.LockType = adLockBatchOptimistic
    Set rsaux.ActiveConnection = cn
    
End Sub

Public Sub ConsultaSql(sql As String)
    If Not rs.State = adStateClosed Then rs.Close
    rs.Open sql, cn, adOpenDynamic, adLockOptimistic
End Sub

Public Function ejecutarcompleto(sql As String)
    If Not rs.State = adStateClosed Then rs.Close
    rs.Open sql, cn, adOpenDynamic, adLockOptimistic
    ejecutarcompleto = rs.Fields(0)
End Function

Public Function existe(sql As String) As Boolean
    If Not rs.State = adStateClosed Then rs.Close
    rs.Open sql, cn, adOpenDynamic, adLockOptimistic
    If rs.RecordCount = 0 Then
        existe = False
    Else
        existe = True
    End If
End Function

Public Sub sentenciaSql(sql As String)
    If Not rsaux.State = adStateClosed Then rsaux.Close
    rsaux.Open sql, cn, adOpenDynamic, adLockOptimistic
End Sub

Public Sub ssSql(sql As String)
    Set rsimprime = New ADODB.Recordset
    rsimprime.CursorLocation = adUseClient
    rsimprime.CursorType = adOpenStatic
    rsimprime.LockType = adLockBatchOptimistic
    Set rsimprime.ActiveConnection = cn
    If Not rsimprime.State = adStateClosed Then rsimprime.Close
    rsimprime.Open sql, cn, adOpenDynamic, adLockOptimistic
End Sub

Public Sub sSql(sql As String)
    Set rsa = New ADODB.Recordset
    rsa.CursorLocation = adUseClient
    rsa.CursorType = adOpenStatic
    rsa.LockType = adLockBatchOptimistic
    Set rsa.ActiveConnection = cn
    If Not rsa.State = adStateClosed Then rsa.Close
    rsa.Open sql, cn, adOpenDynamic, adLockOptimistic
End Sub

Public Function cargarcombo(cbo As ComboBox, rs As ADODB.Recordset, dt As typecombo)
If rs.RecordCount <> 0 Then
    rs.MoveFirst
    Do While Not rs.EOF
        cbo.AddItem Trim(rs.Fields(dt.text).Value)
        cbo.ItemData(cbo.NewIndex) = Trim(rs.Fields(dt.item).Value)
        rs.MoveNext
    Loop
    'cbo.ListIndex = 0
End If
End Function


Public Function validarcombo(cbo As ComboBox, Codigo As Integer)
    Dim i As Integer
    i = 0
    For i = 0 To cbo.ListCount - 1
        If cbo.ItemData(i) = Codigo Then cbo.ListIndex = i
    Next i
End Function
Public Function validarlista(cbo As ListBox, Codigo As Integer)
    Dim i As Integer
    i = 0
    For i = 0 To cbo.ListCount - 1
        If cbo.ItemData(i) = Codigo Then cbo.ListIndex = i
    Next i
        
End Function

Public Function validacion(nro As String)
If nro = "             " Then
    validacion = False
Else
    Coef = "5432765432"
    suma = 0
    For X = 1 To 10
        suma = suma + Val(Mid(nro, X, 1)) * Val(Mid(Coef, X, 1))
    Next
    coc = suma \ 11
    resto = suma - (coc * 11)
    Digito_Ver = Val(Right(nro, 1))
    If resto > 1 Then
       resto = 11 - resto
    End If
    If resto <> Digito_Ver Then
       validacion = False
    Else
       validacion = True
    End If
End If
End Function
